<?php
	#error_reporting(E_ALL);
	#require_once '../../core/autoload.php';

	
	
	function captureAllDirs(Dir $d){
		$dirs = array();
		foreach($d->listDirectories() as $d2){
			$dirs[] = $d2;
			$dirs = array_merge($dirs, captureAllDirs($d2));
		}
		
		return $dirs;
	}
	
	function getModifierName($id){
		return strtolower(substr(token_name($id), 2));
	}
	
	$d = new Dir('/var/www/nd/imp');
	$dirs = captureAllDirs($d);
	
	echo '<pre>';
	
	foreach($dirs as $dir){
		foreach($dir->listFiles() as $f){
			if($f->getMIMEType() == 'text/x-php'){
				$pf = new PHPFileParser($f);
				
				echo 'File <b>' . $f . '</b>' . PHP_EOL;
				
				foreach($pf->getClasses() as $c){
					echo "\t";
					$parent = $c->getParent() == null ? '' : ' Extends <b>' . $c->getParent() . '</b>';
					$implements = count($c->getImplementations()) > 0 ? ' Implements <b>' . implode('</b>, <b>', $c->getImplementations()) . '</b>' : '';
					echo 'Class <b>' . $c->getName() . '</b>' . (count($c->getModifiers()) > 0 ? ' (<i>' . implode('</i>, <i>', array_map('getModifierName', $c->getModifiers())) . '</i>)' : '') . $parent . $implements . PHP_EOL;
					
					foreach($c->getMethods() as $m){
						echo "\t\t";
						echo 'Method <b>' . $m->getName() . '</b>' . (count($m->getModifier()) > 0 ? ' (<i>' . implode('</i>, <i>', array_map('getModifierName', $m->getModifier())) . '</i>)' : '') . PHP_EOL;
					}
					
					echo PHP_EOL;
				}

				foreach($pf->getFunctions() as $f){
					echo "\t";
					echo 'Function <b>' . $f->getName() . '</b>' . PHP_EOL;
				}
				
				echo PHP_EOL;
				
				foreach($pf->getOutterClassTokenIDs() as $id){
					echo "\t";
					echo 'Outter <b>' . token_name($id) . '</b>' . PHP_EOL;
				}
				
				echo PHP_EOL;
			}
		}
	}
	
	echo '</pre>';
?>